package com.guodu.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.guodu.dao.FilemanagerDao;
import com.guodu.dao.UnitsDao;
import com.guodu.dao.UserInfoDao;
import com.guodu.entity.Filemanager;
import com.guodu.entity.Units;
import com.guodu.entity.UserInfo;
import com.guodu.service.FilemanagerService;
import com.guodu.vo.FilemanagerQueryVo;
import com.guodu.vo.FilemanagerVo;


@Service("filemanagerService")
public class FilemanagerServiceImpl implements FilemanagerService {
	
	@Resource
	private FilemanagerDao filemanagerDao;
	
	@Resource
	private UserInfoDao userInfoDao;
	
	@Resource
	private UnitsDao unitsDao;

	@Override
	public long findSizeByVo(FilemanagerQueryVo fqv, Units units) {
		// TODO Auto-generated method stub
		return filemanagerDao.findSizeByVo(fqv,units);
	}

	@Override
	public List<FilemanagerVo> findByVo(FilemanagerQueryVo fqv, Units units,
			int curPage, int pageSize) {
		// TODO Auto-generated method stub
		List<Filemanager> list = filemanagerDao.findByVo(fqv, units, curPage, pageSize);
		List<FilemanagerVo> filemanagerVos = new ArrayList<FilemanagerVo>();
		for (Filemanager filemanager : list) {
			FilemanagerVo filemanagerVo = new FilemanagerVo(filemanager);
			UserInfo userInfo = userInfoDao.findById(filemanager.getCreatePeople());
			if(userInfo.getUnitsId()!=null){
				Units unitsInfo = unitsDao.findById(userInfo.getUnitsId());
				filemanagerVo.setUnitsLevel(unitsInfo.getUnitsLevel());
			}
			filemanagerVo.setUserName(userInfo.getUserName());
			filemanagerVos.add(filemanagerVo);
		}
		return filemanagerVos;
	}

	@Override
	public void saveFile(Filemanager filemanager) {
		// TODO Auto-generated method stub
		filemanagerDao.saveFile(filemanager);
	}

	@Override
	public void delByIds(String[] delIds) {
		// TODO Auto-generated method stub
		for (int i = 0; i < delIds.length; i++) {
			filemanagerDao.delZi(delIds[i]);
		}
		filemanagerDao.delByIds(delIds);
	}

	@Override
	public Filemanager findById(String purchaseId) {
		// TODO Auto-generated method stub
		return filemanagerDao.findById(purchaseId);
	}

}
